<?php

header("Content-Type:text/xml;");
echo '<?xml version="1.0" encoding="utf-8"'.'?'.'>';
echo '<tree id="0">';
echo '<item text="Books" id="-1" open="1" call="1" select="1">';
echo getFolder(0,1);//获得第一级
//open="1" call="1" select="1"
function getFolder($id,$accountId){
  $sql='select id,parentId,name,accountId from folder where accountId='.$accountId.' and parentId='.$id.' order by time asc';
  $query=mysql_query($sql);
    if(mysql_num_rows($query)){
      while($arr=mysql_fetch_array($query)){
        echo '<item text="'.$arr[name].'" id="'.$arr[id].'">';
        getFolder($arr[id],$accountId);
      }
    }
    echo '</item>';
}
echo '</tree>';
?>